<?php
namespace app\api\controller;

use League\CommonMark\Util\UrlEncoder;
use think\facade\Db;
use app\api\controller\ApiComData;

class PublicApi
{

    public static function requestApi($type , $param =[])
    {
        $result = [];
        switch ($type){
            case "Comdata":
                $result = ApiComData::xmlSend($param);
                break;
            case "Comdata2": //非本系统卡号 处理
                $result = ApiComData::xmlSendNew($param);
                break;
            case "Connexpay":
                $result = ApiConData::sendApi($param);
                break;
            case "Connexpay2":
                $result = ApiConData2::sendApi($param);
                break;
            case "Comdata3":
                $result = ApiComData2::xmlSend($param);
                break;
            default:
                break;
        }
        return $result;
    }

    private static function getDefaultHeader()
    {
        $api_url = "https://purchasesapi.connexpay.com/api/v1/token";

        $is_use_public_sandbox = getSetting('is_use_public_sandbox');
        //是否使用公共沙盒
        if($is_use_public_sandbox == 1){
            //公共沙盒
            $api_url        = "https://sandbox-api.marqeta.com/v3";
            $api_user_pwd   = "Mzk2NDc4Y2EtOGY0OC00MWZkLTgxNGQtMmQxZjhhOWUxZjE2OjRkNGZkNmVmLTA4NGEtNDljMy04MzM0LWIwOGQyZjU2MzA4Yw==";
        }else{
            //私有沙盒
            $api_url        = getSetting('api_url');
            $api_user_pwd   = getSetting('api_user_pwd');
        }
        return [
            'host' => $api_url,
            'header' => [
                "accept: application/json",
                "Content-Type: application/json",
                "Authorization: Basic " . $api_user_pwd
            ]
        ];
    }

    public static function rzSend($name , $card)
    {
        $host = "https://qryidcard.market.alicloudapi.com";
        $path = "/lundear/ckidcard";
        $method = "GET";
        $appcode = "af34729dcfe545eeb92a5179bb0ee42f";
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $appcode);
        $querys = "idcard={$card}&name=" . urlencode($name);
        $bodys = "";
        $url = $host . $path . "?" . $querys;
        return http_request($url ,$method , [] , $headers);
    }

}
